using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization;
using EscapeZone.Mapping;
using EscapeZone.Mapping.Elements;

namespace EscapeZone.Serialization
{
    [XmlRoot("Map")]
    public class MapDefinition
    {
        [XmlIgnore]
        public List<IMapElement> MapElements { get; set; }

        [XmlIgnore]
        public List<IDefinition> MapElementDefinitions { get; set; }

        [XmlArray("Walls")]
        public Wall[] Walls
        {
            get { return MapElements.OfType<Wall>().ToArray(); }
            set { MapElements.AddRange(value); }
        }

        [XmlElement]
        public Spawn Spawn
        {
            get { return MapElements.OfType<Spawn>().First(); }
            set { MapElements.Add(value); }
        }

        [XmlElement]
        public GoalZone GoalZone
        {
            get { return MapElements.OfType<GoalZone>().First(); }
            set { MapElements.Add(value); }
        }

        [XmlArray("Guards")]
        public GuardDefinition[] Guard
        {
            get { return MapElementDefinitions.OfType<GuardDefinition>().ToArray(); }
            set { MapElementDefinitions.AddRange(value); }
        }

        [XmlArray("Cameras")]
        public CameraDefinition[] Cameras
        {
            get { return MapElementDefinitions.OfType<CameraDefinition>().ToArray(); }
            set { MapElementDefinitions.AddRange(value); }
        }

        public MapDefinition()
        {
            MapElements = new List<IMapElement>();
            MapElementDefinitions = new List<IDefinition>();
        }
    }
}